package hms.rewards;

import java.sql.*;
import java.util.Arrays;
import java.util.Iterator;

import hms.database.*;

/*This class controls all interactions with 
 * Reward table in DB
 * 
 * @author Edgar Onukwugha*/

public class Reward extends DBRowObject{

	private int reward_program_ID;
	private String description;
	private double discount_amount;
	public int reward_cost;
	public Boolean applicable_to_fee;
	
	public Reward(){
		super();
		reward_program_ID = -1;
		description = "NONE";
		discount_amount = 0.00;
		reward_cost = -1;
		applicable_to_fee = false;
	}
	
	public Reward(int reward_ID){
		super(reward_ID);
	}
	
	/////////////////////////////////////////////////
	/////               SETTERS                //////
	/////////////////////////////////////////////////
		
	public void setRewardProgramID(int i){
		reward_program_ID = i;
		markAsChanged();
	}
	
	public void setDescription(String i){
		description = i;
		markAsChanged();
	}
	
	public void setDiscountAmount(double i){
		discount_amount = i;
		markAsChanged();
	}
	
	public void setRewardCost(int i){
		reward_cost = i;
		markAsChanged();
	}
	
	public void setApplicableToFee(Boolean i){
		applicable_to_fee = i;
		markAsChanged();
	}
	
	/////////////////////////////////////////////////
	/////               GETTERS                //////
	/////////////////////////////////////////////////
	
	public int getRewardProgramID(){
		return reward_program_ID;
	}
	
	public String getDescription(){
		return description;
	}
	
	public double getDiscountAmount(){
		return discount_amount;
	}
	
	public int getRewardCost(){
		return reward_cost;
	}
	
	public Boolean getApplicableToCost(){
		return applicable_to_fee;
	}
	
	@Override
	protected String[] getFieldNames() {
		String[] output = new String[5];
		output[0] = "REWARD_PROGRAM_ID";
		output[1] = "DESCRIPTION";
		output[2] = "DISCOUNT_AMOUNT";
		output[3] = "REWARD_COST";
		output[4] = "APPLICABLE_TO_FEE";
		
		return output;
	}

	@Override
	protected void loadPreparedStatement(PreparedStatement stmt)
			throws SQLException {
		stmt.setInt(1, reward_program_ID);
		stmt.setString(2, description);
		stmt.setDouble(3, discount_amount);
		stmt.setInt(4, reward_cost);
		stmt.setBoolean(5, applicable_to_fee);
		
	}

	@Override
	protected String getUniqueIdentifierFieldName() {
		// TODO Auto-generated method stub
		return "REWARD_ID";
	}

	@Override
	protected String getTableName() {
		// TODO Auto-generated method stub
		return "REWARD";
	}

	@Override
	protected void loadFromDatabase(ResultSet rs) throws SQLException {
		Iterator<String> i = Arrays.asList(getFieldNames()).iterator();
		reward_program_ID = rs.getInt(i.next());
		description = rs.getString(i.next());
		discount_amount = rs.getDouble(i.next());
		reward_cost = rs.getInt(i.next());
		applicable_to_fee = rs.getBoolean(i.next());
	}

	@Override
	protected boolean allowDuplicateRows() {
		// TODO Auto-generated method stub
		return false;
	}

}
